import com.mysql.jdbc.Connection;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UpdBook {
    public static void main(String[] args) throws SQLException {
        MysqlDataSource dataSource=new MysqlDataSource();
        dataSource.setURL("jdbc:mysql://127.0.0.1:3306/java33?characterEncoding=utf8&useSSL=true");
        dataSource.setUser("root");
        dataSource.setPassword("12345678");

        Connection connection= (Connection) dataSource.getConnection();

        String updSql="update booklist set type=? where id=?";
        PreparedStatement statement=connection.prepareStatement(updSql);
        statement.setString(1,"言情小说");
        statement.setInt(2,4);

        int result=statement.executeUpdate();
        System.out.println("执行结果："+result);

        statement.close();
        connection.close();
    }
}
